package com.xyh.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author:kyle
 * @Date:2020/12/11 - 15:21
 * @Project:spring_demo1
 * @Package:com.xyh.log
 * @Version:1.0
 */
@Aspect
@Component("log")
public class LogInfo {
    // 切入点
    @Pointcut("execution(* com.xyh.dao..*(..))")
    public void pointcut(){}

    @Before("pointcut()")
    public void logBefore(){
        System.out.println("------日志：前置增强");
    }

    @After("pointcut()")
    public void after(){
        System.out.println("------日志：最终增强");
    }
    @AfterReturning("pointcut()")
    public void afterReturning(){
        System.out.println("------日志：后置增强");
    }
    @Around("pointcut()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("------日志：环绕增强开始");
        joinPoint.proceed();
        System.out.println("------日志：环绕增强结束");
    }
    @AfterThrowing(value = "pointcut()",throwing = "e")
    public void exception(Throwable e){
        System.out.println("异常日志 " + e.getMessage());
    }

}
